package com.cn.web.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.cn.domain.User;

public class CheckUserNameServlet extends BaseServlet {

	
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doPost(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		//response.setContentType("text/html;charset=utf-8");
		
		String name = request.getParameter("name");
		if(name==null||"".equals(name.trim())){
			response.getWriter().write("<font color='red'>请输入用户名！</font>");
			return;
		}
		User user = us.getUserByUserName(name);
		if(user==null){
			response.getWriter().write("<font color='green'>恭喜您，用户名可用！</font>");
		}else{
			response.getWriter().write("<font color='red'>抱歉，用户名已被占用！</font>");
		}
	}

}
